package com.itheima.entry.dao;


import com.itheima.entry.domain.Student;
import com.itheima.entry.domain.UserInfo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;

public class SaveStudent implements Runnable {
/*
每隔5秒保存一次用户数据
 */
    private ArrayList<Student> list;


    public SaveStudent(ArrayList<Student> list) throws IOException {
        this.list = list;
    }

    @Override
    public void run() {
        while (true) {
            Collections.sort(list);
            try {
                ObjectOutputStream obo = new ObjectOutputStream(new FileOutputStream("D:\\heima_system\\backup\\studentList.txt"));
                obo.writeObject(list);
                obo.flush();
                Thread.sleep(5000);
            } catch (InterruptedException | IOException e) {
                e.printStackTrace();
            }


        }
    }
}
